package com.etime.perfectschool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.etime.perfectschool.mapper.JobMapper;
import com.etime.perfectschool.pojo.Job;
import com.etime.perfectschool.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class JobController {
    @Autowired
    private JobService jobService;

    @Autowired
    private JobMapper jobMapper;

    //  通过工作类型查看兼职
    @GetMapping("/getAllJob")
    public List<Job> getAllJob( String jobType){
        System.out.println(jobType);
        return jobService.getAllJob(jobType);
    }


    //  通过兼职的id修改兼职的状态
    @PutMapping("/changJobState")
    public int changJobState(int jobId,int state){
       Map<String,Object> map=new HashMap<>();
        map.put("jobId",jobId);
        map.put("state",state);
        System.out.println(map);
        return jobService.changJobState(map);
    }

    // 通过jobId删除job
    @DeleteMapping("/deleteJob")
   public int deleteJobByJobId(int jobId){
        return jobService.deleteJobByJobId(jobId);
   }

    // 新增兼职
    @PostMapping("/insertJob")
    public int insertJob(Job job){
        return jobService.insertJob(job);
    }

    //查看全部兼职信息
    @GetMapping("/getAllJobs")
    public Page<Job> getAllJobs(int current, int size,String jobType){
        QueryWrapper<Job> wrapper = new QueryWrapper<>();
        wrapper.like("jobType",jobType);
        Page<Job> page = new Page<>(current,size);
        return jobMapper.selectPage(page,wrapper);
    }

    //根据id查询兼职信息
    @GetMapping("/getAllJobById")
    public Job getAllJobById(int id){
        System.out.println(id);
        return jobMapper.selectById(id);
    }

    //修改发布信息
    @PostMapping("/updateJob")
    public int updateJob(Job job){
        System.out.println(job);
        return jobMapper.updateById(job);
    }

    @GetMapping("/getJob")
    public Page<Job> getJobByPage(int current,int size){
        return jobService.getJobByPage(current,size);
    }
}
